package com.yytek.tddb.api.domain;


import com.yytek.tddb.api.enums.DataTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @ClassDescription: 建表的字段实体类
 */
@Data
@ApiModel("建表的字段实体类")
public class Fields {
    private static final long serialVersionUID = 1L;

    /**
     * 字段名称
     */
    @ApiModelProperty("字段名称")
    private String fieldName;

    /**
     * 字段值
     */
    @ApiModelProperty("字段值")
    private Object fieldValue;

    /**
     * 字段数据类型
     */
    @ApiModelProperty("字段数据类型")
    private DataTypeEnum dataType;

    /**
     * 字段字节大小
     */
    @ApiModelProperty("字段字节大小")
    private Integer size;

    public Fields() {
    }

    public Fields(String fieldName, String dataType, Integer size) {
        this.fieldName = fieldName;
        //根据规则匹配字段数据类型
        switch (dataType.toLowerCase()) {
            case ("jsonobject"):
            case ("string"):
                this.dataType = DataTypeEnum.NCHAR;
                this.size = size;
                break;
            case ("int"):
                this.dataType = DataTypeEnum.INT;
                break;
            case ("bool"):
                this.dataType = DataTypeEnum.BOOL;
                break;
            case ("double"):
                this.dataType = DataTypeEnum.DOUBLE;
                break;
            case ("datetime"):
                if ("eventTime".equals(fieldName))
                    this.fieldName = "eventTime";
                this.dataType = DataTypeEnum.TIMESTAMP;
                break;
        }
    }
}
